import router from '@system.router';
import prompt from '@system.prompt';
import storage from '@system.storage';

export default {
    data: {
        title:'',
        info:'',
        list:[],
        isShow:false,
    },
    onInit(e) {
        this.getInfo()

    },
    getInfo(){
        storage.get({
            key:'list',
            success:(res)=>{
                let data = JSON.parse(res)
                this.list = data.list
                if(this.mainid){
                    this.isShow = true
                    for(let i of this.list){
                        if(i.id == this.mainid){
                            this.title = i.title
                            this.info = i.info
                        }
                    }
                }
            }
        })
    },
    yes(){
        if(!(this.title)){
            prompt.showToast({
                message:'请输入标题'
            })
            return
        }
        if(!(this.info)){
            prompt.showToast({
                message:'请输入内容'
            })
            return
        }
        var timestamp = Date.parse(new Date());
        console.info(timestamp)
        let data = {
            title:this.title,
            info:this.info,
            id:timestamp
        }
        let list = [...this.list,data]
        storage.set({
            key:'list',
            value:JSON.stringify({list:list}),
            success:()=>{
                router.back();
            }
        })
    },
    updateTitle(data){
        this.title = data.value
    },
    updateInfo(data){
        this.info = data.value
    }


}
